package com.cet.designpatterns.interpreter.cc;

import java.util.Arrays;
import java.util.List;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-09-26 11:16
 **/
public class Context {

    private List<String> citys = Arrays.asList("芜湖","池州","安庆","阜阳");
    private List<String> personGroups = Arrays.asList("幼童", "孕妇", "老人");

    private Expression expression;

    public Context() {
        Expression cityExpression = new TerminalExpression(citys);
        Expression personGroupExpression = new TerminalExpression(personGroups);
        expression = new NonterminalExpression(cityExpression, personGroupExpression);
    }

    public void freeTake(String info) {
        boolean result = expression.interpret(info);
        if (result) {
            System.out.println("您是" + info + "，您本次乘车免费！");
        } else {
            System.out.println(info + "，您不是免费人员，本次乘车扣费2元！");
        }
    }
}
